package com.sample.kokou;

import android.content.ContentValues;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SampleDBHelper extends SQLiteOpenHelper {

    public SampleDBHelper(Context context) {
        super(context, "test.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(
            "CREATE TABLE people (" +
            "  id INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "  name VARCHAR, " +
            "  age INTEGER);"
        );
        insertInitialValues(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    private void insertInitialValues(SQLiteDatabase db) {
        ContentValues yamada = new ContentValues();
        yamada.put("name", "山田 浩一郎");
        yamada.put("age", 25);
        db.insert("people", null,yamada);

        ContentValues sakuma = new ContentValues();
        sakuma.put("name", "佐久間 慎吾");
        sakuma.put("age", 37);
        db.insert("people", null, sakuma);

        ContentValues amagi = new ContentValues();
        amagi.put("name", "天城 京子");
        amagi.put("age", 18);
        db.insert("people", null, amagi);
    }
}
